package ru.xeden.web.html.page;

import ru.xeden.core.common.ObjectRegistr;
import ru.xeden.web.html.component.IComponentFactory;
import ru.xeden.web.html.layout.ILayoutFactory;
import ru.xeden.web.html.module.IModule;


/**
 * Регистр фабрик пейджов
 * @author evga
 *
 */
public class PageFactoryRegister
    extends ObjectRegistr<IPageFactory>
{
    public IPage getPageByUrlPiece(String pageName, IModule module)
    {
        GetPageAcceptor acceptor = new GetPageAcceptor(pageName, module);
        accept(acceptor);
        return acceptor.getPage();
    }

    private class GetPageAcceptor
        implements IAcceptor<IPageFactory>
    {
        private String pageName;
        private IPage page;
        private IModule module;
        

        public GetPageAcceptor(String pageName, IModule module)
        {
            this.pageName = pageName;
            this.module = module;
        }

        public boolean accept(IPageFactory factory)
        {
            IPage p = factory.createPage(pageName, module);
            if (p != null)
            {
                this.page = p;
                return false;
            }
            return true;
        }

        public IPage getPage()
        {
            return page;
        }
    }

}
